import canvasAbstract from './canvasAbstract';
import model from '../model/bullet'
import tank from './tank';
import bullet from '../model/bullet'
import player from "../canvas/player"
import audio from "../service/audio"
export default new (class extends canvasAbstract implements ICanvas{
    intervalId = 0
    num(): number {
        return 0;
    }
    model(): BulletIModelAbstract {
        return model
    }
    render(): void {
        this.intervalId = setInterval(() => {
            this.createBullet();
            this.renderModels();
        },50);
    }
    stop(): void {
        clearInterval(this.intervalId);
    }
    createBullet(){
        tank.models.forEach(tank => {
            const isExit = this.models.some(m => m.tank == tank);
            if(!isExit) {
                this.models.push(new bullet(tank))
            }
        })
    }

    addPlayerBullet(){
        this.models.push(new bullet(player.models[0]));
        audio.fire()
    }
})('bullet');